package com.wxx.model;

import org.springframework.util.StringUtils;

public class MsgKey {
	private String key;

	private String clientKey; //默认为0

	private Long tranId; //默认为0
	
	public MsgKey() {
		super();
	}

	public MsgKey(String key) {
		super();
		this.key = key;
		this.clientKey = "0";
		this.tranId = Long.valueOf(0);
	}
	
	public MsgKey(Msg msg) {
		super();
		this.key = msg.getKey();
		this.clientKey = StringUtils.isEmpty(msg.getClientKey()) ? "0" : msg.getClientKey();
		this.tranId = msg.getTranId() == null ? Long.valueOf(0): msg.getTranId();
	}
	
	public MsgKey(String key, String clientKey, Long tranId) {
		super();
		this.key = key;
		this.clientKey = StringUtils.isEmpty(clientKey) ? "0" : clientKey;
		this.tranId = tranId == null ? Long.valueOf(0): tranId;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getClientKey() {
		return StringUtils.isEmpty(clientKey) ? "0" : clientKey;
	}

	public void setClientKey(String clientKey) {
		this.clientKey = StringUtils.isEmpty(clientKey) ? "0" : clientKey;
	}

	public Long getTranId() {
		return tranId == null ? Long.valueOf(0): tranId;
	}

	public void setTranId(Long tranId) {
		this.tranId = tranId == null ? Long.valueOf(0): tranId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((clientKey == null) ? 0 : clientKey.hashCode());
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		result = prime * result + ((tranId == null) ? 0 : tranId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		MsgKey other = (MsgKey) obj;
		if (clientKey == null) {
			if (other.clientKey != null) {
				return false;
			}
		} else if (!clientKey.equals(other.clientKey)) {
			return false;
		}
		if (key == null) {
			if (other.key != null) {
				return false;
			}
		} else if (!key.equals(other.key)) {
			return false;
		}
		if (tranId == null) {
			if (other.tranId != null) {
				return false;
			}
		} else if (!tranId.equals(other.tranId)) {
			return false;
		}
		return true;
	}

}